// ==UserScript==
// @name           csair_checkprice
// @namespace      csair
// @include        http://ec.csair.com/B2C/modules/order/simple/showflights.jsp
// ==/UserScript==

var catagory = 'Kclass';
var lessThan = 500;


function checkPrice(catagory, price)
{
	var KClasses = document.evaluate(
	   "//TD[@class='"+catagory+"']",
	    document,
			null,
			XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
			null);

	var found = 0; 
	for(var i = 0; i < KClasses.snapshotLength; i++)
	{
		var KClass = KClasses.snapshotItem(i);
		var _text = KClass.childNodes[2];

		if(_text)
		{
			var prc = parseInt(_text.nodeValue);
			if(prc <= price)
			{
				GM_log("found cheap airline price = " + _text.nodeValue);
				found++;
			}
		}
	}

	if(found>0)
		alert("found airline cheaper than "+ price);
	else
		history.back();
}

function run()
{
	checkPrice(catagory, lessThan);
}

setTimeout(run, 5000);